package com.zego.wawaji.http.request;

import com.zego.wawaji.base.bean.Common;
import com.zego.wawaji.base.bean.Updata;
import com.zego.wawaji.base.data.BaseData;
import com.zego.wawaji.base.utils.Hosts;
import com.zego.wawaji.third.ThirdConstant;
import com.zego.wawaji.third.pay.bean.Alipay;
import com.zego.wawaji.third.pay.bean.PayWX;
import com.zego.wawaji.third.share.data.ShareData;
import com.zego.wawaji.ui.bean.LoginResult;
import com.zego.wawaji.ui.bean.UpLoadResult;
import com.zego.wawaji.ui.bean.banner.NoticeList;
import com.zego.wawaji.ui.bean.pay.PayList;
import com.zego.wawaji.ui.bean.user.UserDetail;
import com.zego.wawaji.ui.bean.user.newuser.NewUser;
import com.zego.wawaji.ui.bean.wawa.Game.Game;
import com.zego.wawaji.ui.bean.wawa.MyWawaList;
import com.zego.wawaji.ui.bean.wawa.WawaJiList;
import com.zego.wawaji.ui.bean.wawa.WawaList;
import com.zego.wawaji.ui.bean.wawa.send.MySendList;
import com.zego.wawaji.ui.center.about.About;
import com.zego.wawaji.ui.center.address.bean.AddressList;
import com.zego.wawaji.ui.center.credit.bean.CreditConvert;
import com.zego.wawaji.ui.center.credit.bean.CreditList;
import com.zego.wawaji.ui.center.invite.bean.Invite;
import com.zego.wawaji.ui.center.pay.bean.ConsumeList;
import com.zego.wawaji.ui.center.pay.bean.OrderRecordList;
import com.zego.wawaji.ui.center.question.bean.QuestionList;
import com.zego.wawaji.ui.center.transport.bean.StepList;
import com.zego.wawaji.ui.center.wawa.Exchange;
import com.zego.wawaji.ui.coupon.bean.CouponList;
import com.zego.wawaji.ui.play.bean.LuckyUserList;
import com.zego.wawaji.ui.play.bean.PlayInit;
import com.zego.wawaji.ui.rank.bean.AwardList;
import com.zego.wawaji.ui.store.bean.StoreList;
import com.zego.wawaji.ui.store.order.bean.OrderList;
import com.zego.wawaji.ui.view.adDialog.bean.AdInfoList;
import com.zego.wawaji.ui.wawa.synth.bean.Synth;

import java.util.Map;

/**
 * 管理常用的Url参数信息
 * <p>
 * 注意： post请求一定要传postParam参数，因为默认为Get请求
 */
public enum UrlParam {

    // ========================= 测试地址 ==============
    reqPayListTest(Hosts.FATE_IT_GO, "v1/sys_ww_coin/test/get", PayList.class, true),  // 获取充值列表
    reqLoginTest(Hosts.FATE_IT_GO, "v1/user_login/login/test", LoginResult.class, false), // 使用id测试登录

    // ========================= utils工具接口 ==============
    reqSendCode(Hosts.FATE_IT_GO, "v1/fun_utils/send_code", LoginResult.class, false),    // 获取验证码
    uploadFile(Hosts.FATE_IT_OSS, "v1/fun_utils/upload", UpLoadResult.class, false),    // 上传文件
    reqNewVersion(Hosts.FATE_IT_GO, "v1/sys_setting/get_app_new", Updata.class, false),    // 检查更新
    reqAboutMe(Hosts.FATE_IT_GO, "v1/sys_setting/get_about_me", About.class, false),    // 根据参数获取信息
    reqSetting(Hosts.FATE_IT_GO, "v1/sys_setting/get_base", Common.class, true),    // 获取基本配置信息
    reqAdInfo(Hosts.FATE_IT_GO, "v1/sys_ad/get", AdInfoList.class, false),    // 获取广告弹框信息

    // ========================= user_login ==============
    reqVerifyCode(Hosts.FATE_IT_GO, "v1/user_login/login/mobile", LoginResult.class, false),  // 手机号验证码登录
    weChatLogin(Hosts.FATE_IT_GO, "v1/user_login/login/wechat", LoginResult.class, false),    // 微信登录
    getWXAccessToken(ThirdConstant.WECHAT_API_SERVER, "oauth2/access_token", null, false),    // 获取微信AccessToken
    getWXUserInfo(ThirdConstant.WECHAT_API_SERVER, "userinfo", null, false),                  // 获取微信用户资料

    reqMyInfo(Hosts.FATE_IT_GO, "v1/fun_user_info/get", UserDetail.class, true),      // 获取个人资料
    reqUpdateInfo(Hosts.FATE_IT_GO, "v1/user_base/update", null, true),   // 更新用户基本信息
    reqBannerNotice(Hosts.FATE_IT_GO, "v1/sys_notice/get", NoticeList.class, true),  // 获取轮播条公告
    reqRewardNew(Hosts.FATE_IT_GO, "v1/user_detail/reward_new", NewUser.class, true),  // 新用户注册奖励，无邀请码的用户
    reqRewardDaily(Hosts.FATE_IT_GO, "v1/user_detail/reward_daily", null, true),  // 每日礼包领取接口： 不到账
    reqGiveRewardDaily(Hosts.FATE_IT_GO, "v1/user_detail/give_reward_daily", null, true),  // 每日礼包领取接口： 不到账

    // 地址管理
    reqGetAddress(Hosts.FATE_IT_GO, "v1/rec_user_address/get", AddressList.class, true),   // 获取用户地址
    reqUpdataAddress(Hosts.FATE_IT_GO, "v1/rec_user_address/update", AddressList.class, true),   // 修改地址
    reqDefaultAddress(Hosts.FATE_IT_GO, "v1/rec_user_address/update_default", null, true),   // 设置默认地址地址
    reqAddAddress(Hosts.FATE_IT_GO, "v1/rec_user_address/add", AddressList.class, true),   // 增加地址
    reqDeleAddress(Hosts.FATE_IT_GO, "v1/rec_user_address/delete", null, true),   // 删除地址

    // ========================= wawaji ==============
    reqWawajiList(Hosts.FATE_IT_GO, "v1/wwj_base/get_all", WawaJiList.class, true), // 获取娃娃机列表
    reqWawaList(Hosts.FATE_IT_GO, "v1/sys_ww/get_all", WawaList.class, true), // 获取娃娃列表
    reqMyWawa(Hosts.FATE_IT_GO, "v1/rec_wwj_game/get_myww", MyWawaList.class, true),  // 获取各种我的娃娃列表
    reqAskSend(Hosts.FATE_IT_GO, "v1/rec_wwj_game/get_isasksend", MySendList.class, true),  // 获取已经申请的娃娃列表
    reqOrderRecord(Hosts.FATE_IT_GO, "v1/rec_wwj_order/get_order", OrderRecordList.class, true), // 获取充值记录
    reqSpendRecord(Hosts.FATE_IT_GO, "v1/rec_wwj_spend/get", ConsumeList.class, true), // 获取消费记录
    reqPointRecord(Hosts.FATE_IT_GO, "v1/rec_wwj_point/get", CreditList.class, true), // 获取积分记录

    reqSendChooseWawa(Hosts.FATE_IT_GO, "v1/rec_wwj_game/send", null, true), // 可选择娃娃发货

    reqExchangeWawa(Hosts.FATE_IT_GO, "v1/rec_wwj_game/exchange_ww", Exchange.class, true), // 兑换娃娃为积分/币
    reqGameApply(Hosts.FATE_IT_GO, "v1/rec_wwj_game/request", PlayInit.class, true), // 预约时调用，判断娃娃币是否充足
    reqGameAdd(Hosts.FATE_IT_GO, "v1/rec_wwj_game/add", Game.class, true), // 开始游戏通知服务端
    reqExchangeWwcoin(Hosts.FATE_IT_GO, "v1/rec_wwj_point/exchange_wwcoin", CreditConvert.class, true), // 积分兑换娃娃币
    reqTransport(Hosts.FATE_IT_GO, "v1/rec_wwj_transport/get_tran", StepList.class, true), // 获取物流信息
    reqTransportID(Hosts.FATE_IT_GO, "v1/rec_wwj_transport/get_one", null, true), // 获取物流ID
    reqGameCatch(Hosts.FATE_IT_GO, "v1/rec_wwj_game/get_catch", LuckyUserList.class, true), // 获取物流信息
    reqRoomjoin(Hosts.FATE_IT_GO, "v1/send_msg_wwj/room_join", null, true), // 进入游戏房间时调用一次
    reqUpdateMsg(Hosts.FATE_IT_GO, "v1/wwj_base/update_msg_json", null, true), // 更新聊天记录
    reqGetMsg(Hosts.FATE_IT_GO, "v1/wwj_base/get_msg_json", null, true), // 获取聊天记录
    reqGameFirst(Hosts.FATE_IT_GO, "v1/rec_wwj_game/is_first_fail", null, true), // 是否是首抓
    reqGameOver(Hosts.FATE_IT_GO, "v1/rec_wwj_game/over", null, true), // 结束游戏通知服务端

    reqShareInfo(Hosts.FATE_IT_GO, "v1/user_detail/get_yqcode", ShareData.class, true), // 获取邀请信息
    reqShareWXCircle(Hosts.FATE_IT_GO, "v1/user_detail/reward_share", null, true), // 分享朋友圈成功奖励，每日一次
    reqYQIp(Hosts.FATE_IT_GO, "v1/rec_user_yq/check", null, true), // 通知服务器用户的ip地址
    reqYQCode(Hosts.FATE_IT_GO, "v1/user_detail/reward_yqcode", null, true), // 通知服务器用户邀请码

    reqGetGameResult(Hosts.FATE_IT_GO, "v1/rec_wwj_game/status", null, true), // 获取游戏结果

    // ========================= pay ==============
    reqPayType(Hosts.FATE_IT_GO, "v1/sys_setting/pay_status", null, true),  // 获取可用支付方式
    reqPayListNew(Hosts.FATE_IT_GO, "v1/sys_ww_coin/get_with_ban", PayList.class, true),  // 获取充值列表
    reqAlipay(Hosts.FATE_IT_GO, "v1/fun_pay/alipay_app_add", Alipay.class, true),  // 获取支付宝充值订单
    reqWxPay(Hosts.FATE_IT_GO, "v1/fun_pay/wxpay_app_add", PayWX.class, true),  // 获取微信充值订单

    // ========================= 商城 ==============
    reqGoodsList(Hosts.FATE_IT_GO, "v1/mall_goods/get", StoreList.class, true),  // 获取商品列表
    reqGoodsExchange(Hosts.FATE_IT_GO, "v1/mall_goods/exchange", null, true),  // 兑换商品
    reqGoodsSendList(Hosts.FATE_IT_GO, "v1/rec_mall_order/get", OrderList.class, true),    // 商品申请发货列表
    reqUpdateStatus(Hosts.FATE_IT_GO, "v1/rec_mall_order/update_status", null, true),    // 更改订单状态

    // ========================= 充值排行榜 ==================
    reqAwardList(Hosts.FATE_IT_GO, "v1/sys_activity/award", AwardList.class, true),    // 我的奖品列表
    reqAwardSend(Hosts.FATE_IT_GO, "v1/sys_activity/send", null, true),    // 实体奖品申请发货
    reqAwardRechange(Hosts.FATE_IT_GO, "v1/sys_activity/recharge", null, true),    // 虚拟奖品申请发货
    reqAwardUpdate(Hosts.FATE_IT_GO, "v1/sys_activity/update_status", null, true),    // 更改订单状态
    reqLuckWawa(Hosts.FATE_IT_GO, "v1/sys_ww/luck_ww", null, true),   // 开宝箱
    reqRewardWawaCoin(Hosts.FATE_IT_GO, "v1/user_detail/reward_first_recharge", null, true),   // 首充7天奖励领币

    // ========================= 优惠券 ==============
    reqUserCoupon(Hosts.FATE_IT_GO, "v1/rec_user_coupon/get", CouponList.class, true),  // 获取用户优惠券列表

    // ========================= 合成娃娃 ==============
    reqComposeWawa(Hosts.FATE_IT_GO, "v1/sys_ww/compose", Synth.class, true),
    reqExchangeMaterial(Hosts.FATE_IT_GO, "v1/sys_ww/exchange_daimeng_ww", null, true),     // 兑换合成碎片

    // ========================= 邀请页 ==============
    reqInvitePage(Hosts.FATE_IT_GO, "v1/user_detail/invite_page", Invite.class, true),  // 邀请页数据
    reqInviteBox(Hosts.FATE_IT_GO, "v1/user_detail/invite_box", null, true), // 邀请页开宝箱

    // ========================= 问题反馈 ==============
    reqQuestionList(Hosts.FATE_IT_GO, "v1/sys_question/", QuestionList.class, true), // 常见问题列表
    reqQuestionAdd(Hosts.FATE_IT_GO, "v1/rec_feedback/add", null, true),  // 反馈问题
    reqMyQuestion(Hosts.FATE_IT_GO, "v1/rec_feedback/get", QuestionList.class, true),  // 我的反馈
    reqQuestionStatus(Hosts.FATE_IT_GO, "v1/rec_feedback/feed_status", null, true),  // 改变状态


    // 下载奖励
    reqRewardDownload(Hosts.FATE_IT_GO, "v1/user_detail/reward_download", null, true),

    // 最后一个，占位
    LastUrlParam("");

    // -------------------------------内部处理逻辑----------------------------------------

    private String host = Hosts.HOST_URL;    //请求host
    private String spliceUrl = null;            //接口url，与host拼接得到完整url
    private boolean needLogin = false;          //请求是否需要登录才会发送
    private Class<? extends BaseData> parseClass = null;//请求返回体解析类

    // --------------构造方法 start--------------

    /**
     * host+接口url+解析bean
     */
    UrlParam(final String host, final String spliceUrl, final Class<? extends BaseData> parseClass, final boolean needLogin) {
        this.host = host;
        this.spliceUrl = spliceUrl;
        this.parseClass = parseClass;
        this.needLogin = needLogin;
    }

    /**
     * 接口url+解析bean+是否需要登录
     */
    UrlParam(final String spliceUrl, final Class<? extends BaseData> parseClass, final boolean needLogin) {
        this(Hosts.HOST_URL, spliceUrl, parseClass, needLogin);
    }

    /**
     * 接口url+解析bean
     */
    UrlParam(final String spliceUrl, final Class<? extends BaseData> parseClass) {
        this(spliceUrl, parseClass, false);
    }

    /**
     * 接口url+是否需要登录
     */
    UrlParam(final String spliceUrl, final boolean needLogin) {
        this(spliceUrl, null, needLogin);
    }

    /**
     * 接口url
     */
    UrlParam(final String spliceUrl) {
        this(spliceUrl, null);
    }

    // --------------构造方法 end--------------

    /**
     * 重设请求host
     *
     * @param host host地址
     * @return UrlParam
     */
    public UrlParam resetHost(String host) {
        this.host = host;
        return this;
    }

    /**
     * 重设接口url，特殊情况使用
     *
     * @param spliceUrl 接口url
     */
    public void resetSpliceUrl(String spliceUrl) {
        this.spliceUrl = spliceUrl;
    }

    /**
     * 是否需要登录才能发送的请求
     *
     * @return boolean值
     */
    public boolean isNeedLogin() {
        return needLogin;
    }

    /**
     * 获取完整Url
     *
     * @return url
     */
    public String getFinalUrl() {
        if (host.equals(Hosts.NO_HOST)) {
            return spliceUrl;
        }
        return host + spliceUrl;
    }

    /**
     * 获取一个实现了BaseData接口的实例
     *
     * @return 有Class的newInstance生成的实例
     */
    public BaseData getBaseData() {
        BaseData baseData = null;
        try {
            if (parseClass != null) baseData = parseClass.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baseData;
    }

    /**
     * 获取完整拼接参数的Url，用于缓存url等
     *
     * @param param 需要传送的参数
     * @return spliceUrl
     */
    public String getEntireUrl(Map<String, Object> param) {
        String url = this.spliceUrl;
        if (param != null) {
            for (Object o : param.entrySet()) {
                Map.Entry entry = (Map.Entry) o;
                Object key = entry.getKey();
                Object val = entry.getValue();
                url = url.replaceAll("\\{" + key.toString() + "\\}", val.toString());
            }
        }
        if (!host.equals(Hosts.NO_HOST)) {
            url = host + url;
        }
        return url;
    }
}